/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beanControl;

import Utils.Helper;
import Utils.JDBCHelper;
import Utils.StringUtility;
import beanInfo.collateral;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTable;

/**
 *
 * @author lyan
 */
public class collateralControl {

    ArrayList<String> listColumn = new ArrayList<String>();
    ArrayList<String> listValue = new ArrayList<String>();
    collateral col = new collateral();

    public void listCollateral(JTable table) {
        String sql = "select * from Collateral";
        String[] header = {"CollateralID", "CollateralName", "Quantity", "ValuesAsset", "Features", "ProfileID", "Status"};
        Helper.loadDataTable(sql, table, header);
    }

    public void insertCollateral(collateral col) {
        Object[] values = {col.getCollateralName(), col.getQuantity(), col.getValuesAsset(),
            col.getFeatures(), col.getProfileID(), col.getStatus()};
        JDBCHelper.excuteInsertPlaceHolder("Collateral", 6, values);
        Helper.successMessage("Insert  successfull", "wanning");
    }

    public void updatecollateral(collateral col) {
        String[] objColumn = {"CollateralName,  Quantity,ValuesAsset, Features, ProfileID,Status"};
        String[] objValues = {col.getCollateralName(), String.valueOf(col.getQuantity()), col.getValuesAsset(), col.getFeatures(),
            String.valueOf(col.getProfileID()), col.getStatus()};

        listColumn = (ArrayList<String>) StringUtility.ArrayToArrayList(objColumn);
        listValue = (ArrayList<String>) StringUtility.ArrayToArrayList(objValues);
        JDBCHelper.executeUpdate("Collateral", listColumn, listValue, "CollateralID", String.valueOf(col.getCollateralID()));
        Helper.successMessage("Update Sucessful", "wanning");
    }

    public void DeleteLoanProfile(collateral col) {


        JDBCHelper.excuteDelete("CollateralID", "LoanProfile", String.valueOf(col.getCollateralID()));
        Helper.successMessage("Delete successfull", "wanning");


    }
     public int getMaxZprofileID() {
        int id = 0;
        try {
            String sql = "select max (ProfileID) from Collateral";
            ResultSet rs = JDBCHelper.excuteSelect(sql);
            if (rs.next()) {
                id = rs.getInt(1);
            }
        } catch (SQLException ex) {
            Logger.getLogger(purposesControl.class.getName()).log(Level.SEVERE, null, ex);
        }
        return id;
    }
}
